#if DDD
using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using GoogleMobileAds.Api;
using UnityEngine;
using UnityEngine.Networking;

namespace Topifish.Ads {
    /// <summary>
    /// google广告代理,对接google的广告业务
    /// </summary>
    public class AdmobAgent : MonoBehaviour {
        static AdmobAgent instance;
        public static AdmobAgent GetInstance {
            get {
                if (instance == null) {
                    GameObject gg = new GameObject("AdmobAgent");
                    MonoBehaviour.DontDestroyOnLoad(gg);
                    instance = gg.AddComponent<AdmobAgent>();
                }
                return instance;
            }
        }

        /// <summary>
        /// 奖励视频结果回调
        /// </summary>
        public event Action<E_AdCallbackType> d_RewardVideoResultCallBack;
        /// <summary>
        /// 插页广告结果回调
        /// </summary>
        public event Action<E_AdCallbackType> d_InterstitialResultCallBack;
        /// <summary>
        /// 当前设备是否支持google广告
        /// </summary>
        public bool CurrentDeviceIsSupport() {
            return !isTest;
        }
        /// <summary>
        /// 是否初始化完成
        /// </summary>
        public bool IsInitComplete {
            get {
                return isInitComplete;
            }
        }
        bool isInitComplete = false;

        /// <summary>
        /// 间质全屏广告是否准备完成
        /// </summary>
        public bool IsInterstitialReady() {
            if (isInitComplete == false) {
                Debug.LogWarning("admobAgent_初始化未完成___");
                return false;
            }
            bool isLoad = interstitial.IsLoaded();
            // Debug.Log("是否加载完成========插页广告================"+ isLoad);
            return isLoad;

        }
        /// <summary>
        /// 间质全屏广告开启
        /// </summary>
        public void ShowInterstitial() {
            if (isInitComplete == false) {
                Debug.LogWarning("admobAgent_初始化未完成___");
            }
            //Debug.Log("showInterstitial==============================");
            if (interstitial.IsLoaded()) {
                Debug.Log("admobAgent_----开始显示- 插页广告 -------------");
                interstitial.Show();
            } else {
                //interstitial.Load(GetAdRequest());
                Debug.Log("admobAgent_-----开始显示- -插页广告 -没有准备好 -------------");
            }
        }


        /// <summary>
        /// 视频广告是否准备完成
        /// </summary>
        public bool IsRewardedVideoReady() {
            if (isInitComplete == false) {
                Debug.LogWarning("admobAgent_初始化未完成___");
                return false;
            }
            bool isLoad = rewardVideo.IsLoaded();
            //Debug.Log("admobAgent_是否加载完成=================奖励视频=========" + isLoad);
            return isLoad;
        }
        /// <summary>
        /// 离线广告是否加载完成
        /// </summary>
        public bool IsOffLineRewardedVideoReady() {
            if (isInitComplete == false) {
                Debug.LogWarning("admobAgent_初始化未完成___");
                return false;
            }
            bool isLoad = offLineRewardVideo.IsLoaded();
            //Debug.LogError("是否加载完成===================离线视频======="+ isLoad);
            return isLoad;
        }
        public bool IsSkillUpgradingVideoReady() {
            if (isInitComplete == false) {
                Debug.LogWarning("admobAgent_初始化未完成___");
                return false;
            }
            bool isLoad = skillUpgradingVideo.IsLoaded();
            //Debug.LogError("是否加载完成===================技能升级视频======="+ isLoad);
            return isLoad;
        }
        /// <summary>
        /// 显示奖赏视频---激励-双倍单局收益
        /// </summary>
        public void ShowRewardedVideo() {
            if (isInitComplete == false) {
                Debug.LogWarning("admobAgent_初始化未完成___");
                return;
            }
            if (rewardVideo.IsLoaded()) {
                //AudioManager.Ins.StopALL();  //播放广告的时候，关闭全部声音
                Debug.Log("admobAgent_-----开始播放  奖励视频-------------");
                rewardVideo.Show();
            } else {
                Debug.Log("admobAgent_-----开始播放  奖励视频-没有准备好 -------------");
            }
        }
        /// <summary>
        /// 显示离线奖赏视频---
        /// </summary>
        public void ShowOffLineRewardedVideo() {
            if (isInitComplete == false) {
                Debug.LogWarning("admobAgent_初始化未完成___");
                return;
            }
            if (offLineRewardVideo.IsLoaded()) {
                //AudioManager.Ins.StopALL();  //播放广告的时候，关闭全部声音
                Debug.Log("admobAgent_-----开始播放  离线视频-------------");
                offLineRewardVideo.Show();
            } else {
                Debug.Log("admobAgent_---开始播放  离线视频-没有准备好 -------------");
            }
        }

        public void ShowSkillUpgradingVideo() {
            if (isInitComplete == false) {
                Debug.LogWarning("admobAgent_初始化未完成___");
                return;
            }
            if (skillUpgradingVideo.IsLoaded()) {
                //AudioManager.Ins.StopALL();  //播放广告的时候，关闭全部声音
                Debug.Log("admobAgent_-----开始播放  技能升级视频-------------");
                skillUpgradingVideo.Show();
            } else {
                Debug.Log("admobAgent_---开始播放  技能升级视频-没有准备好 -------------");
            }
        }


        internal List<int[]> messageListener = new List<int[]>();
        internal List<Action> eventLinsterner = new List<Action>();
        float lastUpdateTime;
        void Update() {
            if (isInitComplete == false) {
                return;
            }
            if (messageListener.Count > 0) {
                lock (messageListener) {
                    for (int i = 0; i < messageListener.Count; i++) {
                        int[] sss = messageListener[i];
                        try {
                            HandleMessage(sss);
                        } catch {
                            Debug.Log("错误__admob解析消息出错");
                        }
                    }
                    messageListener.Clear();
                }
            }
            if (eventLinsterner.Count > 0) {
                foreach (var event0 in eventLinsterner) {
                    event0();
                }
                eventLinsterner.Clear();
            }
            lastUpdateTime = Time.realtimeSinceStartup;
            if (Time.realtimeSinceStartup - refreshStartTime > 10) {
                refreshStartTime = Time.realtimeSinceStartup;
                for (int i = 0; i < adList.Count; i++) {
                    try {
                        if (adList[i].IsLoadFail) {
                            if (adList[i].LoadTime + failRefreshInterval < Time.realtimeSinceStartup) {
                                adList[i].Load();
                            }
                        } else {
                            if (adList[i].LoadTime + defaultRefreshInterval < Time.realtimeSinceStartup) {
                                adList[i].Load();
                            }
                        }
                    } catch (Exception ex) {
                        Debug.LogErrorFormat("出错_{0}_{1}", ex.Message, ex.StackTrace);
                    }
                }
            }
        }
        float refreshStartTime;
        const float failRefreshInterval = 600;//失败了 十分钟后重新刷新
        const float defaultRefreshInterval = 3600;//成功了 一小时刷新一次

        void HandleMessage(int[] msg) {
            switch ((E_AdUnitType)msg[1]) {
                case E_AdUnitType.e00_banner:
                    break;
                case E_AdUnitType.e01_interstitial:
                    if (d_InterstitialResultCallBack != null) {
                        try {
                            d_InterstitialResultCallBack((E_AdCallbackType)msg[2]);
                        } catch (Exception ex) {
                            Debug.Log("admobAgent_插页广告出错__" + ex);
                        }
                    }
                    break;
                case E_AdUnitType.e02_offLineVideo:
                    if (d_RewardVideoResultCallBack != null) {
                        try {
                            d_RewardVideoResultCallBack((E_AdCallbackType)msg[2]);
                        } catch (Exception ex) {
                            Debug.Log("admobAgent_视频广告logic处理出错___" + ex);
                        }
                    }
                    break;
                case E_AdUnitType.e03_skillUpgrading:
                    if (d_RewardVideoResultCallBack != null) {
                        try {
                            d_RewardVideoResultCallBack((E_AdCallbackType)msg[2]);
                        } catch (Exception ex) {
                            Debug.Log("admobAgent_视频广告logic处理出错___" + ex);
                        }
                    }
                    break;
                case E_AdUnitType.e04_rewardVideo:
                    if (d_RewardVideoResultCallBack != null) {
                        try {
                            d_RewardVideoResultCallBack((E_AdCallbackType)msg[2]);
                        } catch (Exception ex) {
                            Debug.Log("admobAgent_视频广告logic处理出错___" + ex);
                        }
                    }
                    break;
            }
        }

        C_Banner banner = new C_Banner(E_AdUnitType.e00_banner);
        C_Interstitial interstitial = new C_Interstitial(E_AdUnitType.e01_interstitial);
        C_RewardVideo rewardVideo = new C_RewardVideo(E_AdUnitType.e04_rewardVideo);
        C_RewardVideo offLineRewardVideo = new C_RewardVideo(E_AdUnitType.e02_offLineVideo);
        C_RewardVideo skillUpgradingVideo = new C_RewardVideo(E_AdUnitType.e03_skillUpgrading);
        List<C_baseAd> adList = new List<C_baseAd>();

        public void Init(bool isTest) {
            Debug.Log("admobAgent_当前设备是否支持谷歌广告----" + (!isTest));
            //topifis新版账号
            AccountConfig accountConfig = AccountConfig.TopifishNewAdccount;

            MobileAds.SetiOSAppPauseOnBackground(true);
            MobileAds.Initialize(accountConfig.appId);
            interstitial.Init(accountConfig.interstitialId);
            rewardVideo.Init(accountConfig.videoId);
            offLineRewardVideo.Init(accountConfig.offLineVideoId);
            skillUpgradingVideo.Init(accountConfig.skillUpgradingId);
            banner.Init(accountConfig.bannerId);

            rewardVideo.Load();
            offLineRewardVideo.Load();
            skillUpgradingVideo.Load();
            interstitial.Load();

            adList.Add(banner);
            adList.Add(interstitial);
            adList.Add(offLineRewardVideo);
            adList.Add(skillUpgradingVideo);
            adList.Add(rewardVideo);

            isInitComplete = true;
        }
        bool isTest;
        static AdRequest GetAdRequest() {
            //Debug.Log("是否测试-------------------" + isTest);
            AdRequest.Builder builder = new AdRequest.Builder();
            if (AdmobAgent.GetInstance.isTest) {
                builder.AddTestDevice(AdRequest.TestDeviceSimulator);
                builder.AddTestDevice(SystemInfo.deviceUniqueIdentifier.ToUpper());
                builder.SetGender(Gender.Male);


            }
            //builder.TagForChildDirectedTreatment(false);
            //builder.AddExtra("color_bg", "9B30FF");
            builder.AddKeyword("Game");
            return builder.Build();
        }

        public void StartLoadAds() {
            banner.Load();
            //经过15再次检查视频广告是否加载失败，失败再次加载
            this.StartCoroutine(I_Delayed(15, delegate () {
                for (int i = 0; i < adList.Count; i++) {
                    try {
                        if (adList[i].IsLoadFail && adList[i].adType==E_AdmobType.e03_RewardVideo) {
                            adList[i].Load();
                        } 
                    } catch (Exception ex) {
                        Debug.LogErrorFormat("出错_{0}_{1}", ex.Message, ex.StackTrace);
                    }
                }
            }));
        }

        /// <summary>
        /// 奖励视频回调类型
        /// </summary>
        public enum E_AdCallbackType {
            /// <summary>
            /// 加载视频
            /// </summary>
            e01_onAdLoaded = 1,
            /// <summary>
            /// 视频加载失败
            /// </summary>
            e02_onAdFailedToLoad = 2,
            /// <summary>
            /// 打开视频
            /// </summary>
            e08_onAdOpened = 8,
            /// <summary>
            /// 启动-开始
            /// </summary>
            e10_onAdStarted = 10,
            /// <summary>
            /// 视频被关闭
            /// </summary>
            e12_onAdClosed = 12,
            /// <summary>
            /// 奖励
            /// </summary>
            e16_onAdRewarded = 16,
            /// <summary>
            /// 视频播放完成
            /// </summary>
            e19_onAdCompleted = 19,
        }
        internal enum E_AdmobType {
            e01_Banner = 1,
            e02_Interstitial = 2,
            e03_RewardVideo = 3,
        }
        internal enum E_AdUnitType {
            e00_banner=0,
            e01_interstitial=1,
            e02_offLineVideo=2,
            e03_skillUpgrading=3,
            e04_rewardVideo=4,
        }

        internal class C_baseAd {
            public E_AdmobType adType;
            public E_AdUnitType adUnitType;
            public C_baseAd(E_AdUnitType adUnitType) {
                this.adUnitType = adUnitType;
            }
            List<int> currentCallbackMsgList = new List<int>();
            /// <summary>
            /// 是否正在加载中
            /// </summary>
            protected static bool isLoading;
            private float loadTime;
            bool isLoadFail;
            public bool IsLoadFail {
                get {
                    return isLoadFail;
                }
            }
            public float LoadTime {
                get {
                    return loadTime;
                }
            }
            public void OnLoadFail() {
                isLoadFail = true;
                loadTime = AdmobAgent.GetInstance.lastUpdateTime;
            }
            public void OnAdClose() {
                isLoadFail = false;
                Load();
            }
            public virtual void Load() {
                request = GetAdRequest();
                currentCallbackMsgList.Clear();
                isLoadFail = false;
                isLoading = true;
                loadTime = AdmobAgent.GetInstance.lastUpdateTime;
                Debug.LogFormat("AdmobAgent_加载广告__{0}____{1}", adTypeString[(int)adType], adUnitString[(int)adUnitType]);
            }
            protected AdRequest request;
            public virtual void Show() {
                Debug.LogFormat("AdmobAgent_显示广告__{0}____{1}", adTypeString[(int)adType], adUnitString[(int)adUnitType]);
            }

            protected void OnAdLoaded(object sender, EventArgs args) {
                SendMessage( E_AdCallbackType.e01_onAdLoaded, sender, args);
            }
            protected void OnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args) {
                SendMessage( E_AdCallbackType.e02_onAdFailedToLoad, sender, args.Message);
                OnLoadFail();
            }
            protected void OnAdOpening(object sender, EventArgs args) {
                SendMessage( E_AdCallbackType.e08_onAdOpened, sender, args);
            }
            protected void OnAdStarted(object sender, EventArgs args) {
                SendMessage( E_AdCallbackType.e10_onAdStarted, sender, args);
            }
            protected void OnAdRewarded(object sender, EventArgs args) {
                SendMessage(E_AdCallbackType.e16_onAdRewarded, sender, args);
            }
            protected void OnAdClosed(object sender, EventArgs args) {
                SendMessage( E_AdCallbackType.e12_onAdClosed, sender, args);
                OnAdClose();
            }
            protected void OnAdLeavingApplication(object sender, EventArgs args) {
                SendMessage( E_AdCallbackType.e19_onAdCompleted, sender, args);
            }


            protected static Dictionary<int, string> adCallbackString = new Dictionary<int, string>() { { 1, "Ad开始加载" }, { 2, "Ad加载失败" }, { 8, "Ad打开" }, { 10, "Ad启动开始" }, { 12, "Ad被关闭" }, { 16, "Ad奖励" }, { 19, "Ad播放完成" } };
            protected static Dictionary<int, string> adTypeString = new Dictionary<int, string>() { { 1, "横幅广告" }, { 2, "插页广告" }, { 3, "奖励视频" } };
            protected static string[] adUnitString = new string[] { "横幅", "插页", "离线收益", "技能升级", "奖励视频" };
            protected void SendMessage( E_AdCallbackType adCallbackType, object sender, object args) {
                isLoading = false;
                if (adType == E_AdmobType.e03_RewardVideo) {
                    adUnitType = C_RewardVideo.currentAdUnitType;
                }
                if (currentCallbackMsgList.Contains((int)adCallbackType)) {
                    Debug.LogErrorFormat("admobAgent_收到回调消息_重复_________{0}=={1}__{2}__________{3}___{4}", adTypeString[(int)adType], adUnitString[(int)adUnitType], adCallbackString[(int)adCallbackType], sender, args);
                } else {
                    Debug.LogFormat("admobAgent_收到回调消息___________{0}=={1}__{2}__________{3}___{4}", adTypeString[(int)adType], adUnitString[(int)adUnitType], adCallbackString[(int)adCallbackType], sender, args);
                    currentCallbackMsgList.Add((int)adCallbackType);
                    AdmobAgent.GetInstance.messageListener.Add(new int[] { (int)adType, (int)adUnitType, (int)adCallbackType });
                }
            }
        }
        internal class C_Banner: C_baseAd {
            private BannerView bannerView;
            string adUnitId;
            public C_Banner(E_AdUnitType adUnitType):base(adUnitType) {}
            public void Init(string adUnitId) {
                this.adUnitId = adUnitId;
                this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);

                index = (int)AdPosition.Bottom;
                bannerView.OnAdLoaded += OnAdLoaded;
                bannerView.OnAdFailedToLoad += OnAdFailedToLoad;
                bannerView.OnAdOpening += OnAdOpening;
                bannerView.OnAdClosed += OnAdClosed;
                bannerView.OnAdLeavingApplication += OnAdLeavingApplication;
                adType = E_AdmobType.e01_Banner;
            }
            int index;
            public override void Load() {
                if (this.bannerView != null) {
                    this.bannerView.Destroy();
                }
                Init(adUnitId);
                base.Load();
                bannerView.LoadAd(request);
            }
            public override void Show() {
                base.Show();
                bannerView.Show();
            }
            public void Hide() {
                bannerView.Hide();
            }
        }
        internal class C_Interstitial: C_baseAd {
            private InterstitialAd interstitial;
            string adUnitId;
            public C_Interstitial(E_AdUnitType adUnitType) : base(adUnitType) { }
            public void Init(string adUnitId) {
                this.adUnitId = adUnitId;
                this.interstitial = new InterstitialAd(adUnitId);
                this.interstitial.OnAdLoaded += OnAdLoaded;
                this.interstitial.OnAdFailedToLoad += OnAdFailedToLoad;
                this.interstitial.OnAdOpening += OnAdOpening;
                this.interstitial.OnAdClosed += OnAdClosed;
                this.interstitial.OnAdLeavingApplication += OnAdLeavingApplication;
                adType = E_AdmobType.e02_Interstitial;
            }
            public override void Load() {
                if (this.interstitial != null) {
                    this.interstitial.Destroy();
                }
                Init(adUnitId);
                base.Load();
                this.interstitial.LoadAd(request);
            }
            public bool IsLoaded() {
                return interstitial.IsLoaded();
            }
            public override void Show() {
                base.Show();
                interstitial.Show();
            }
        }
        internal class C_RewardVideo: C_baseAd {
            string adUnitId;
            public static E_AdUnitType currentAdUnitType;
            public C_RewardVideo(E_AdUnitType adUnitType) : base(adUnitType) { }
            static bool isRegisterEvent;
            public void Init(string adUnitId) {
                this.adUnitId = adUnitId;
                if (isRegisterEvent == false) {
                    isRegisterEvent = true;
                    RewardBasedVideoAd.Instance.OnAdLoaded += OnAdLoaded;
                    RewardBasedVideoAd.Instance.OnAdFailedToLoad += OnAdFailedToLoad;
                    RewardBasedVideoAd.Instance.OnAdOpening += OnAdOpening;
                    RewardBasedVideoAd.Instance.OnAdStarted += OnAdStarted;
                    RewardBasedVideoAd.Instance.OnAdRewarded += OnAdRewarded;
                    RewardBasedVideoAd.Instance.OnAdClosed += OnAdClosed;
                    RewardBasedVideoAd.Instance.OnAdLeavingApplication += OnAdLeavingApplication;
                }
                adType = E_AdmobType.e03_RewardVideo;
            }
            public override void Load() {
                if (isLoading) {
                    return;
                } else {
                    Debug.LogFormat("重复Load___{0}________", adUnitString[(int)adUnitType]);
                }
                ////设置玩家Id
                //string userId = DateTime.Now.ToString("yyyy年MM月dd号 HH点mm分ss秒");
                //userId = GetMD5(userId);
                //RewardBasedVideoAd.Instance.SetUserId(userId);

                base.Load();
                currentAdUnitType = adUnitType;
                RewardBasedVideoAd.Instance.LoadAd(request, adUnitId);
            }
            public bool IsLoaded() {
                return RewardBasedVideoAd.Instance.IsLoaded();
            }
            public override void Show() {
                base.Show();
                RewardBasedVideoAd.Instance.Show();
            }
        }


        #region-----工具方法---------------------
        static string GetMD5(string ss) {
            using (MD5 m5 = MD5.Create()) {
                byte[] zData = Encoding.UTF8.GetBytes(ss);
                zData = m5.ComputeHash(zData);
                m5.Clear();
                StringBuilder bb5 = new StringBuilder();
                for (int i = 0; i < zData.Length; i++) {
                    bb5.Append(zData[i].ToString("x2"));
                }
                return bb5.ToString();
            }
        }
        internal IEnumerator I_Delayed(float time, Action callback) {
            yield return new WaitForSeconds(time);
            callback();
        }
        #endregion
    }
    /// <summary>
    /// google Admob账号信息
    /// </summary>
    public class AccountConfig {
        public string appId;
        public string bannerId;
        public string interstitialId;
        public string videoId;
        public string offLineVideoId;
        public string skillUpgradingId;
        //未使用
        public string bannerVideoId = "---";
        public string nativeBannerId = "---";


        /// <summary>
        /// 官方测试账号
        /// </summary>
        public static AccountConfig OfficialTestAccount {
            get {
                if (_OfficialTestAccount == null) {
                    _OfficialTestAccount = new AccountConfig();
                    _OfficialTestAccount.appId = "ca-app-pub-3940256099942544~1458002511";
                    _OfficialTestAccount.bannerId = "ca-app-pub-3940256099942544/2934735716";
                    _OfficialTestAccount.interstitialId = "ca-app-pub-3940256099942544/4411468910";
                    _OfficialTestAccount.videoId = "ca-app-pub-3940256099942544~1458002511";
                    _OfficialTestAccount.offLineVideoId = "ca-app-pub-3940256099942544~1458002511";
                    _OfficialTestAccount.skillUpgradingId = "ca-app-pub-3940256099942544~1458002511";
                }
                return _OfficialTestAccount;
            }
        }
        static AccountConfig _OfficialTestAccount;



        /// <summary>
        /// Topifish旧版本账号
        /// </summary>
        public static AccountConfig TopifishOldAdccount {
            get {
                if (_TopifishOldAdccount == null) {
                    _TopifishOldAdccount = new AccountConfig();
                    _TopifishOldAdccount.appId = "ca-app-pub-4181258008446320~8455697681";
                    _TopifishOldAdccount.videoId = "ca-app-pub-4181258008446320/6375780512";
                    _TopifishOldAdccount.offLineVideoId = "ca-app-pub-4181258008446320/5717853706";
                    _TopifishNewAdccount.skillUpgradingId = "ca-app-pub-8039872577109440/5717853706";
                    _TopifishOldAdccount.bannerId = "ca-app-pub-4181258008446320/4649557886";
                    _TopifishOldAdccount.nativeBannerId = "ca-app-pub-4181258008446320/8612853623";
                    _TopifishOldAdccount.interstitialId = "ca-app-pub-4181258008446320/9438850133";
                    _TopifishOldAdccount.bannerVideoId = "ca-app-pub-4181258008446320/8612853623";
                }
                return _TopifishOldAdccount;
            }
        }
        static AccountConfig _TopifishOldAdccount;




        /// <summary>
        /// Topifish新版本账号
        /// </summary>
        public static AccountConfig TopifishNewAdccount {
            get {
                if (_TopifishNewAdccount == null) {
                    _TopifishNewAdccount = new AccountConfig();
                    _TopifishNewAdccount.appId = "ca-app-pub-8039872577109440~6269250872";
                    _TopifishNewAdccount.videoId = "ca-app-pub-8039872577109440/8839573895";
                    _TopifishNewAdccount.offLineVideoId = "ca-app-pub-8039872577109440/4353533975";
                    _TopifishNewAdccount.skillUpgradingId = "ca-app-pub-8039872577109440/3942470433";
                    _TopifishNewAdccount.bannerId = "ca-app-pub-8039872577109440/3637797224";
                    _TopifishNewAdccount.interstitialId = "ca-app-pub-8039872577109440/6241330717";
                }
                return _TopifishNewAdccount;
            }
        }
        static AccountConfig _TopifishNewAdccount;
    }

    /// <summary>
    /// 检测设备是否支持google广告
    /// </summary>
    public class CheckDeviceIsSupport {
        public void InitCheck() {
            if (Application.platform == RuntimePlatform.Android && (Application.systemLanguage == SystemLanguage.Chinese || Application.systemLanguage == SystemLanguage.ChineseSimplified)) {
                AdmobAgent.GetInstance.StartCoroutine(RequestGoogle(delegate (bool isSuccess) {
                    bool isTest = !isSuccess;
                    AdmobAgent.GetInstance.Init(isTest);
                }));
            } else {
                AdmobAgent.GetInstance.StartCoroutine(AdmobAgent.GetInstance.I_Delayed(0.3f,delegate(){
                    AdmobAgent.GetInstance.Init(false);
                }));
            }
        }
        IEnumerator RequestGoogle(Action<bool> callback) {
            string url = "https://www.google.com/";
            using (UnityWebRequest www = UnityWebRequest.Get(url)) {
                Debug.LogWarning("开始RequestGoogle----" + Time.realtimeSinceStartup);
                www.timeout = 2;
                yield return www.SendWebRequest();
                if (www.error != null) {
                    Debug.Log(www.error);
                    Debug.LogWarning("RequestGoogle----Fail--" + Time.realtimeSinceStartup);
                    callback(false);
                } else {
                    if (www.responseCode == 200) {//200表示接受成功
                        Debug.Log(www.downloadHandler.text);
                        Debug.LogWarningFormat("RequestGoogle---success---{0}---{1}-", Time.realtimeSinceStartup, www.responseCode);
                        callback(true);
                    } else {
                        Debug.LogWarningFormat("RequestGoogle----Fail---{0}---{1}-", Time.realtimeSinceStartup, www.responseCode);
                        callback(false);
                    }
                }
            }
        }
    }

}
#endif